﻿using System.Collections.Generic;
using System.Composition;
using Unread.Business.Data.Storage.Interfaces;
using Windows.Foundation;
using Windows.Storage;
using Windows.Storage.Pickers;

namespace Unread.Business.Data.Storage
{
    [Export(typeof(IFileWriterPicker))]
    internal class FileWriterPicker : IFileWriterPicker
    {
        private readonly Windows.Storage.Pickers.FileSavePicker _fileSavePicker;

        public FileWriterPicker()
        {
            _fileSavePicker = new Windows.Storage.Pickers.FileSavePicker();
        }

        public IAsyncOperation<StorageFile> PickSaveFileAsync(PickerLocationId startLocation, string suggestedFilename, IList<KeyValuePair<string, IList<string>>> fileTypes)
        {
            _fileSavePicker.SuggestedStartLocation = startLocation;
            _fileSavePicker.SuggestedFileName = suggestedFilename;

            foreach (var fileType in fileTypes)
            {
                _fileSavePicker.FileTypeChoices.Add(fileType);
            }

            return _fileSavePicker.PickSaveFileAsync();
        }
    }
}
